how use the dispose method for close the connection
3419
10-Nov-2010
explain it
Shankar M
25-Feb-2013Shankar M
25-Feb-2013Shankar M
25-Feb-2013yash Singh
18-Dec-2010Dispose() method permanently removes connection object from memory and the resource no longer exists for any further processing.
string constring = "Server=(local);Database=my; User Id=sa; Password=sa";
SqlConnection sqlcon = new SqlConnection(constring);
sqlcon.Open(); // connection is open
try
{
// code here which will be execute
}
catch
{
// code will be execute when error occurred in try block
}
finally
{
sqlcon.Dispose(); // close and desroy the connection object
}